package com.nkzy;

//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
public class Main {
    public static void main(String[] args) {
        //TIP Press <shortcut actionId="ShowIntentionActions"/> with your caret at the highlighted text
        // to see how IntelliJ IDEA suggests fixing it.
        int sum = 0; // 初始化累加器

        // 使用 for 循环，从1遍历到100
        for (int i = 1; i <= 100; i++) {
            int previousSum = sum; // 保存当前累加前的值
            sum += i; // 将当前数字 i 累加到 sum
            System.out.println(previousSum + " + " + i + " = " + sum); // 输出累加步骤
        }

        // 循环结束后输出总和
        System.out.println("1到100的累加和为: " + sum);

    }
    }
